package com.stylefeng.guns.rest.modular.App.service.impl;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.model.CommonKeyValue;
import com.stylefeng.guns.core.model.Pager;
import com.stylefeng.guns.rest.modular.App.service.IOrderTypeService;
import com.stylefeng.guns.rest.modular.App.dao.OrderTypeMapper;
import com.stylefeng.guns.rest.modular.App.model.OrderType;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**

 * 线路类型 Service 实现 
 * @author sasazaixian
 * @Date 2018-11-15 14:16
 */
@Service
public class OrderTypeServiceImpl extends ServiceImpl<OrderTypeMapper,OrderType> implements IOrderTypeService {

    @Resource
    private OrderTypeMapper orderTypeMapper;


    /**
     * 查询线路类型列表
     * @param orderType 线路类型对象
     * @return
     */
    public List<OrderType> selectListOrderType(OrderType orderType,String token)throws Exception{
        if(orderType==null){
            orderType=new OrderType();
            orderType.setOtType("0");
        }
        if(orderType.getOtType()==null){
            orderType.setOtType("0");
        }
        return  this.orderTypeMapper.selectListOrderType(orderType);
    }
    /**
	 * 分页查询线路类型列表
     * @param pager 分页对象
     * @return
     */
    public  Map pageListOrderType(Pager pager,String token) throws Exception{
        Page page=new Page(pager.getPageNumber(),pager.getPageSize());
        OrderType orderType=(OrderType)pager.getObj();
        if(orderType==null){
            orderType=new OrderType();
            orderType.setOtType("0");
        }
        if(orderType.getOtType()==null){
            orderType.setOtType("0");
        }
        page.setRecords(orderTypeMapper.selectListOrderType(page,orderType));
        List<OrderType> list = page.getRecords();
        Map mapDate = new HashMap();
        mapDate.put("rows", list);
        mapDate.put("total", page.getTotal());
        mapDate.put("page", page.getCurrent());
        mapDate.put("pageCount", page.getPages());
        return mapDate;
    }
    /**
     * 同一个事务 互斥锁查询
     * @param orderType 线路类型对象
     * @return
     */
    public  List<OrderType> selectListOrderTypeForUpdate(OrderType orderType)throws Exception{
        return  this.orderTypeMapper.selectListOrderTypeForUpdate(orderType);
    }
    /**
     * 通过主键id查询的线路类型列表
     * @param id 主键id
     * @return
     */
    public  OrderType findOrderTypeById(String id,String token)throws Exception{
        return  this.orderTypeMapper.findOrderTypeById(id);
    }

    /**
     * 新增线路类型数据
     * @param orderType  线路类型对象
     * @return
     */
    @Transactional
    public int insertOrderType(OrderType orderType,String token) throws Exception {
        return 0;
    }

    /**
     * 更新线路类型数据
     * @param orderType 线路类型对象
     * @return
     */
    @Transactional
    public int updateOrderType(OrderType orderType,String token) throws Exception {
        return 0;
    }
    /**
     * 查询线路类型返回key-Value属性
     * @param orderType 系统操作对象
     * @return
     */
    public List<CommonKeyValue> optionsOrderType(OrderType orderType,String token) throws Exception {
        if(orderType==null){
            orderType=new OrderType();
            orderType.setOtType("0");
        }
        List<OrderType> listOrderType=this.orderTypeMapper.selectListOrderType(orderType);
        List<CommonKeyValue> listOptions=new ArrayList<CommonKeyValue>();
        for(OrderType item:listOrderType){
            CommonKeyValue opts=new CommonKeyValue();
            opts.setId(""+item.getOtCode());
            opts.setValue(item.getOtName());
            listOptions.add(opts);
        }
        return listOptions;
    }
}
